package libra.openfeign.callService;

import java.util.HashMap;
import java.util.Map;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 被OpenFeign调用的Controller
 * @author libra
 */
@RestController
@RequestMapping("service")
public class OpenFeignServiceController {
	private static final Map info = Map.of("from", "service");

	// 测试服务调用请求
	@RequestMapping("exec")
	public Object exec() {
		Map copyOf = new HashMap(info);
		copyOf.putAll( Map.of("method", "exec()") );
		return copyOf;
	}
	
	// 测试请求超时
	@RequestMapping("timeout")
	public Object timeout() {
		try {
			Thread.sleep(10000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		Map copyOf = new HashMap(info);
		copyOf.putAll( Map.of("method", "timeout()") );
		return copyOf;
	}
	
	// 测试请求处理异常
	@RequestMapping("ex")
	public Object ex() {
		int i = 1/0;
		Map copyOf = new HashMap(info);
		copyOf.putAll( Map.of("method", "ex()") );
		return copyOf;
	}
}
